home *** CD-ROM | disk | FTP | other *** search
- ;
- ; HTTPGet - V1.00 Written by Rob Hutchinson for the Blitz TCP Lib as
- ; an example. Also very useful program :) I plan to expand it Soon.
- ;
- ; Note that you need the NEW version of the EFMUILib (v2) to compile
- ; this code. http://www.satanicdreams.com/
- ;
-
-
- ;
- ; About strings.
- ;
- a$="HTTPGet - (C)opyright By Rob Hutchinson"+Chr$(10)
- a$+"Version: 1.00 [020+]"+Chr$(10)
- a$+"Compilation date: 18.03.2000"+Chr$(10)
- a$+Chr$(10)
- a$+Chr$(27)+"bFREEWARE"+Chr$(10)
- a$+Chr$(27)+"n"+Chr$(10)
- a$+"Satanic Dreams Software Homepages:"+Chr$(10)
- a$+"http://www.satanicdreams.com/"+Chr$(10)+Chr$(10)
- a$+"Rob Hutchinson <"+Chr$(27)+"8rob@satanicdreams.com"+Chr$(27)+"0>"+Chr$(10)
- a$+"Special thanks to:"+Chr$(10)
- a$+"David McMinn"+Chr$(10)
- a$+"Douglas McLaughlin"
-
- WBStartup
- !StackOpen{6000}
-
- FindScreen 0
- MaxLen pat$=512
- pat$="RAM:"
-
- If ReadFile(0,"HTTPGet.CFG")
- FileInput 0
- LastPath$=Edit$(512)
- LastFile$=Edit$(2000)
- LastChex$=Edit$(512)
- CloseFile 0
- EndIf
-
- DefaultOutput
-
- pat$=LastPath$
-
- ;####################################################################
-
- MUIApplicationTitle "HTTPGet"
- MUIApplicationVersion "$VER: HTTPGet 1.00 (18.03.2000)"
- MUIApplicationCopyright "(C)1999 SDS, Robert Hutchinson."
- MUIApplicationAuthor "Robert Hutchinson & David McMinn"
- MUIApplicationDescription "Download files via HTTP from the net."
- MUIApplicationBase "HTTPGET"
-
- #BME_APP = 1
- #BME_Window1 = 2
- #BME_MainGroup = 3
- #BME_Text = 4
- #BME_PathGroup = 5
- #BME_PathLabel = 6
- #BME_PathSmaller = 7
- #BME_PathString = 8
- #BME_PathPoper = 9
-
- #BME_GroupStr = 10
- #BME_ViewLabel = 11
- #BME_ViewCheck = 12
- #BME_GetFileLabel = 13
- #BME_GetString = 14
- #BME_GetButton = 15
- #BME_GroupPro = 16
- #BME_LabelProgress = 17
- #BME_GaugeProgress = 18
- #BME_AbortButton = 19
-
- #EB_CloseRequest = -1
- #EB_Ack = 10
- #EB_GoGetIt = 11
- #EB_AbortIt = 12
- #EB_PopDrawer = 13
-
- #HTP_MenuList_MenuList = 20
- #HTP_Menu_HTTPGet = 21
- #HTP_MenuItem_Iconify = 5000
- #HTP_MenuItem_AboutHTP = 5006
- #HTP_UData_AboutHTP = 30
- #HTP_MenuItem_AboutMUI = 5007
- #HTP_MenuItem_Quit = 5008
-
- #HTP_Menu_Transfer = 22
- #HTP_MenuItem_Retrieve = 5020
- #HTP_UData_Retrieve = 31
- #HTP_MenuItem_AbortTransfer = 5021
- #HTP_UData_AbortTransfer = 32
-
- #HTP_Menu_Settings = 23
- #HTP_MenuItem_SaveSetup = 5062
-
- #BME_ShowReqHere = 24
-
-
- GTMenuTitle 0,0,"HTTPGet"
- GTMenuItem 0,0,0,0,"Iconify","I",0,#HTP_MenuItem_Iconify
- GTMenuItem 0,0,0,1
- GTMenuItem 0,0,0,2,"About HTTPGet...","?",0,#HTP_MenuItem_AboutHTP
- GTMenuItem 0,0,0,3,"About MUI...","",0,#HTP_MenuItem_AboutMUI
- GTMenuItem 0,0,0,4
- GTMenuItem 0,0,0,5,"Quit","Q",0,#HTP_MenuItem_Quit
-
- GTMenuTitle 0,1,"Transfer"
- GTMenuItem 0,0,1,0,"Retrieve File","R",0,#EB_GoGetIt ;#HTP_MenuItem_Retrieve
- GTMenuItem 0,0,1,1,"Abort Transfer","A",0,#EB_AbortIt ;#HTP_MenuItem_AbortTransfer
-
- GTMenuTitle 0,2,"Settings"
- GTMenuItem 0,0,2,0,"Save Setup","S",0,#HTP_MenuItem_SaveSetup
-
-
- ;#########################################################################
-
- Macro di MUISet `1,#MUIA_Disabled,True End Macro
- Macro en MUISet `1,#MUIA_Disabled,False End Macro
- Macro mdi MUISet `1,#MUIA_Menuitem_Enabled,0 End Macro
- Macro men MUISet `1,#MUIA_Menuitem_Enabled,1 End Macro
-
-
- MUIText #BME_Text,"Idle!",True
-
- MUILabel #BME_PathLabel,"To _Path:",0
- MUIKeyBetterString #BME_PathString,LastPath$,512,"t"
- MUIPopButton #BME_PathPoper,#MUII_PopDrawer
- MUIAddObjsHGroup #BME_PathSmaller,#BME_PathString,#BME_PathPoper
- MUICreateHGroup #BME_PathSmaller
- MUIGroupHSpacing #BME_PathSmaller,1
- MUIAddObjsHGroup #BME_PathGroup,#BME_PathLabel,#BME_PathSmaller
- MUICreateHGroup #BME_PathGroup
-
- MUILabel #BME_ViewLabel,"_View:",0
- MUIKeyCheckMark #BME_ViewCheck,Val(LastChex$),"v"
- MUILabel #BME_GetFileLabel,"Get _File:",0
- MUIAddTags #BME_GetString,#MUIA_String_AdvanceOnCR,True
- MUIKeyBetterString #BME_GetString,LastFile$,2000,"f"
- MUISimpleButton #BME_GetButton,"_Retrieve!"
- MUISet #BME_GetButton,#MUIA_Text_SetVMax,False
- MUIWeight #BME_GetButton,5
- MUIAddObjsHGroup #BME_GroupStr,#BME_ViewLabel,#BME_ViewCheck,#BME_GetFileLabel,#BME_GetString,#BME_GetButton
- MUICreateHGroup #BME_GroupStr
-
- MUILabel #BME_LabelProgress,"Progress:",0
- MUIAddTags #BME_GaugeProgress,#MUIA_Text_PreParse,Null(Chr$(27)+"c")
- MUIText #BME_GaugeProgress,"Welcome to HTTPGet V1.00 - TCP Example",True
-
- MUIAddObjsHGroup #BME_GroupPro,#BME_LabelProgress,#BME_GaugeProgress
- MUICreateHGroup #BME_GroupPro
-
- MUISimpleButton #BME_AbortButton,"Abort Transfer!"
- !di{#BME_AbortButton}
-
- MUIAddObjsVGroup #BME_MainGroup,#BME_Text,#BME_PathGroup,#BME_GroupStr,#BME_GroupPro,#BME_AbortButton
- MUICreateVGroup #BME_MainGroup
-
- MUICycleChains 1,#BME_PathString,#BME_PathPoper,#BME_ViewCheck,#BME_GetString,#BME_GetButton,#BME_AbortButton
-
- MUIShortHelp #BME_PathString,"A path on disk to download the file(s) to."+Chr$(10)+"Files will take the download name."
- MUIShortHelp #BME_PathPoper,"Select a directory from disk with a path requester."
- MUIShortHelp #BME_ViewCheck,"View file with multiview after downloading."+Chr$(10)+"Note that partial files will be displayed."
- MUIShortHelp #BME_GetString,"Put the URL of the path here."+Chr$(10)+"Should always start with 'http://'"
- MUIShortHelp #BME_GetButton,"Get the entered file from the net."+Chr$(10)+"This will fail if your not online."
- MUIShortHelp #BME_AbortButton,"Abort current transfer."+Chr$(10)+"This button is only active when a download is in progress."
-
- MUICreateMenu #HTP_MenuList_MenuList,0,0,#HTP_Menu_HTTPGet,#HTP_Menu_Transfer,#HTP_Menu_Settings
- MUISetMenu #BME_Window1,#HTP_MenuList_MenuList
-
- MUICreateWindow #BME_Window1,"TCP - HTTPGet V1.00: By Rob Hutchinson 2000","WIN1",#BME_MainGroup
- MUIAddSubWindow #BME_Window1
-
- ;###########################################################################
-
- If MUICreateApplication<>True ; If the application fails to be generated,
- JMP Do_ProgramClose ; we terminate the task.
- EndIf ; Note: This does not open the window.
-
- MUIApplicationObj #BME_APP
-
- MUIFindUData #HTP_UData_Retrieve,#HTP_MenuList_MenuList,#EB_GoGetIt ;#HTP_MenuItem_Retrieve
- MUIFindUData #HTP_UData_AbortTransfer,#HTP_MenuList_MenuList,#EB_AbortIt ;#HTP_MenuItem_AbortTransfer
- MUIFindUData #HTP_UData_AboutHTP,#HTP_MenuList_MenuList,#HTP_MenuItem_AboutHTP
-
- MUINotifyApp #BME_Window1,#MUIA_Window_CloseRequest,1,#EB_CloseRequest
- MUINotifyApp #BME_GetButton,#MUIA_Pressed,0,#EB_GoGetIt
- MUINotifyApp #BME_AbortButton,#MUIA_Pressed,0,#EB_AbortIt
- MUINotifyApp #BME_PathPoper,#MUIA_Pressed,0,#EB_PopDrawer
-
- If MUIOpenWindow(#BME_Window1)=False
- JMP Do_ProgramClose
- EndIf
-
- !mdi{#HTP_UData_AbortTransfer}
-
- FSize.l=0
-
-
-
- Repeat
- Delay_ 1
- Mev.l=MUIEvent
- If DoEventsNow.l
- Tev.l=TCPEvent
- Else
- Tev.l=0
- EndIf
-
- Select Mev
- Case #EB_GoGetIt
-
- HTTPFile$=MUIGetString$(#BME_GetString)
- If Len(HTTPFile$)<10
- MUITextContents #BME_Text,"Host too short!"
- Else
- If UCase$(Left$(HTTPFile$,7))<>"HTTP://"
- MUITextContents #BME_Text,"Incorrect address! No HTTP://"
- Else
- h=Instr(HTTPFile$,"/",8)
- host$=Mid$(HTTPFile$,8,h-8)
- doc$=Mid$(HTTPFile$,h,Len(HTTPFile$))
- countit.w=0
-
- For a.w=Len(HTTPFile$) To 1 Step -1
- countit.w+1
- mi$=Mid$(HTTPFile$,a,1)
- If mi$="/"
- HIFile$=Right$(HTTPFile$,(countit.w-1))
- a=1
- EndIf
- Next a
-
- getstr$="GET "+HTTPFile$+Chr$(13)+Chr$(10)
-
- If TCPOpen
- fail.l=TCPCreateSocket(0,Off,#TCP_SOCK_Read|#TCP_SOCK_Write,20,0)
- If fail.l = #TCP_SOCK_Ok
-
- MUISet #BME_Window1,#MUIA_Window_Sleep,True
- MUITextContents #BME_Text,"Looking up hostname..."
- OurSockStatus.l=TCPConnectSocket(0,host$,80)
- MUISet #BME_Window1,#MUIA_Window_Sleep,False
- If OurSockStatus.l=#TCP_CONN_CONNECTING
- DoEventsNow.l=1
- !en{#BME_AbortButton}
- !men{#HTP_UData_AbortTransfer}
- !mdi{#HTP_UData_Retrieve}
- !mdi{#HTP_UData_AboutHTP}
- !di{#BME_GroupStr}
- !di{#BME_PathGroup}
- MUITextContents #BME_Text,"Host found!..."
- Else
- Select OurSockStatus.l
- Case #TCP_CONN_FailHostResolve
- MUITextContents #BME_Text,"Unable to resolve hostname. FAILED!"
- Case #TCP_CONN_FailNoConnect
- MUITextContents #BME_Text,"Not connected. FAILED!"
- Case #TCP_CONN_FailError
- MUITextContents #BME_Text,"Fatal error. FAILED!"
- End Select
- TCPRemoveSocket 0
- EndIf
-
- Else
- ;
- ; Some failures.
- ;
- Select fail.l
- Case #TCP_SOCK_FailTimeout
- MUITextContents #BME_Text,"Could not set timeout. FAILED!"
- Case #TCP_SOCK_FailAsync
- MUITextContents #BME_Text,"Could not set async. FAILED!"
- Case #TCP_SOCK_FailNoSock
- MUITextContents #BME_Text,"Could not create sock. FAILED!"
- End Select
- EndIf
- Else
- MUITextContents #BME_Text,"No BSDSocket.library. Please Start TCP/IP Stack!"
- EndIf
-
- EndIf
- EndIf
-
- Case #EB_AbortIt
- If TCPAvail
- CloseFile 0
- FSStr$="Got "+Str$(FSize.l)+" bytes! Average CPS: "+Str$(CPS.l)+" (Partial File)."
- !di{#BME_AbortButton}
- !mdi{#HTP_UData_AbortTransfer}
- !men{#HTP_UData_Retrieve}
- !men{#HTP_UData_AboutHTP}
- !en{#BME_GroupStr}
- !en{#BME_PathGroup}
- MUISet #BME_GaugeProgress,#MUIA_Text_Contents,&FSStr$
- FSize.l=0
- CPS.l=0
- TCPRemoveSocket 0
- DoEventsNow.l=0
- Tev=0
- TCPClose
- DefaultOutput
- MUITextContents #BME_Text,"Transfer interupted!..."
- JSR Do_Read
- Else
- MUITextContents #BME_Text,"Cannot abort right now!..."
- EndIf
-
- Case #EB_PopDrawer
- MUISet #BME_Window1,#MUIA_Window_Sleep,True
- NPa$=ASLPathRequest$("Select a download path..",pat$)
- If NPa$<>""
- MUISetString #BME_PathString,NPa$
- EndIf
- MUISet #BME_Window1,#MUIA_Window_Sleep,False
-
- ;###########################################################################################
-
- Case #HTP_MenuItem_Iconify
- MUISet #BME_APP,#MUIA_Application_Iconified,True
-
- Case #HTP_MenuItem_AboutHTP
- MUIRequest #BME_Window1,0,"HTTPGet, Program Information","Ok, I Read it!",Chr$(27)+"c"+a$
-
- Case #HTP_MenuItem_AboutMUI
- MUIDoMethod #BME_APP,#MUIM_Application_AboutMUI,MUIObjLoc(#BME_Window1)
-
- Case #HTP_MenuItem_Quit
- Mev = #EB_CloseRequest
-
- Case #HTP_MenuItem_SaveSetup
- JSR Do_SaveSetup
-
- End Select
-
- If Tev>0
- If (OurSockStatus.l=#TCP_CONN_CONNECTING) AND TCPIsReadEvent(0) OR TCPIsWriteEvent(0)
- err.l=TCPSocketError(0)
- If err
- JSR Do_Error
- Else
- OurSockStatus.l=0
- ;
- ; Now connected..
- ;
- MUITextContents #BME_Text,"Connected to server: "+host$
- TCPSetStates 0,#TCP_SOCK_Read
- TCPNPrint 0,getstr$
- Outfile$=MUIGetString$(#BME_PathString)
- Outfile$+HIFile$
- If WriteFile(0,Outfile$)
- FileOutput 0
- Else
- MUITextContents #BME_Text,"Write failed. Closing connection!"
- !di{#BME_AbortButton}
- !mdi{#HTP_UData_AbortTransfer}
- !men{#HTP_UData_Retrieve}
- !men{#HTP_UData_AboutHTP}
- !en{#BME_GroupStr}
- !en{#BME_PathGroup}
- FSStr$="FAILED!"
- MUISet #BME_GaugeProgress,#MUIA_Text_Contents,&FSStr$
- DoEventsNow.l=0
- FSize.l=0
- CPS.l=0
- TCPRemoveSocket 0
- TCPClose
- DefaultOutput
- EndIf
- TimerReset
- EndIf
- Else
- If Tev
- If TCPIsReadEvent(0)
- err.l=TCPSocketError(0)
- If err
- JSR Do_Error
- Else
- Reed$=TCPReadSocket$(0)
- If Reed$=""
- CloseFile 0
- MUITextContents #BME_Text,"Download complete..."
- FSStr$=Str$(FSize.l)+" bytes saved! Average CPS: "+Str$(CPS.l)
- !di{#BME_AbortButton}
- !mdi{#HTP_UData_AbortTransfer}
- !men{#HTP_UData_Retrieve}
- !men{#HTP_UData_AboutHTP}
- !en{#BME_GroupStr}
- !en{#BME_PathGroup}
- MUISet #BME_GaugeProgress,#MUIA_Text_Contents,&FSStr$
- DoEventsNow.l=0
- FSize.l=0
- CPS.l=0
- TCPRemoveSocket 0
- TCPClose
- DefaultOutput
- JSR Do_Read
- Else
- FSize.l+Len(Reed$)
- DSecs.l=Ticks/50
- If DSecs.l<1 Then DSecs.l=1
- If FSize.l OR DSecs.l Then CPS.l=FSize.l/DSecs.l
- If CPS<0 Then CPS=0
- FSStr$="Bytes transfered: "+Str$(FSize.l)+" - "+Str$(CPS.l)+" CPS."
- MUISet #BME_GaugeProgress,#MUIA_Text_Contents,&FSStr$
- Print Reed$
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
- EndIf
-
- Until Mev = #EB_CloseRequest
-
-
- Do_ProgramClose:
- If DoEventsNow.l=1
- CloseFile 0
- TCPRemoveSocket 0
- TCPClose
- EndIf
-
- JSR Do_SaveSetup
-
- !StackClose
- End
-
- Do_Read:
- If MUIGet(#BME_ViewCheck,#MUIA_Selected)
- Execute_ "Run >NIL: SYS:Utilities/Multiview "+Chr$(34)+Outfile$+Chr$(34),0,0
- EndIf
- RTS
-
- Do_Error:
- MUITextContents #BME_Text,"ERROR #"+Str$(err)+": "+TCPErrorString$
- ;
- ; Close all socket stuff.
- ;
- CloseFile 0
- !di{#BME_AbortButton}
- !mdi{#HTP_UData_AbortTransfer}
- !men{#HTP_UData_Retrieve}
- !men{#HTP_UData_AboutHTP}
- !en{#BME_GroupStr}
- !en{#BME_PathGroup}
- FSize.l=0
- CPS.l=0
- TCPRemoveSocket 0
- DoEventsNow.l=0
- Tev=0
- TCPClose
- DefaultOutput
- MUITextContents #BME_Text,"Transfer interupted!..."
- RTS
-
- Do_SaveSetup:
- If WriteFile(1,"HTTPGet.CFG")
- FileOutput 1
- NPrint MUIGetString$(#BME_PathString)
- NPrint MUIGetString$(#BME_GetString)
- NPrint MUIGet(#BME_ViewCheck,#MUIA_Selected)
- CloseFile 1
- EndIf
- RTS
-
-
-